﻿using System;
using System.Windows.Forms;
using LeakView.common;
using log4net;

namespace LeakView.view
{
    public partial class ViewDebug : UserControl
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(ViewDebug));

        public ViewDebug()
        {
            InitializeComponent();
            if (!CSharpUtilities.IsDesignMode())
            {
                this.debugChart1.reset();
                this.debugChart2.reset();
            }
        }

        public void start()
        {

            /*
            if (!MainModule.pair.Value.Valid)
            {
                log.Info("open debug fail because pair data is invalid.");
                return;
            }


            AnyConfig config = AnyConfigs.get("DEBUG");
            Any aHeadPort = config.get("head_port");
            Any aTailPort = config.get("tail_port");
            int portHead = aHeadPort.GetOrDefault(6789);
            int portTail = aTailPort.GetOrDefault(6789);

            AjaxLeakPair pair = MainModule.pair.Value.Value;

            string headHost = hostFromUrl(pair.head.url);
            string tailHost = hostFromUrl(pair.tail.url);
            */

            this.debugChart1.Start(true);
            this.debugChart2.Start(false);

        }

        public void stop()
        {
            this.debugChart1.Stop();
            this.debugChart2.Stop();
        }

        private string hostFromUrl(string urlString)
        {
            Uri uri = new Uri(urlString);
            return uri.Host;
        }
    }
}
